package com.elitetyc.customview.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

/**
 * Created by elitetyc on 2019/5/22.
 * Describe:
 */
public class BottomDialogAdapter extends RecyclerView.Adapter<BottomDialogAdapter.ViewHolder> {


    private Context mContext;
    private List<String> stringList;
    public BottomDialogAdapter(Context mContext, List<String> stringList) {
        this.mContext = mContext;
        this.stringList = stringList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        TextView textView = new TextView(mContext);
        return new ViewHolder(textView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.textView.setText(stringList.get(i));
    }

    @Override
    public int getItemCount() {
        return stringList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        TextView textView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = (TextView) itemView;
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClick!=null){
                        onItemClick.onItemClickLister(getLayoutPosition());
                    }
                }
            });
        }
    }


    public interface onItemClick{
        void onItemClickLister(int pos);
    }

    private onItemClick onItemClick;

    public BottomDialogAdapter.onItemClick getOnItemClick() {
        return onItemClick;
    }

    public void setOnItemClick(BottomDialogAdapter.onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }
}
